<%@ page contentType="text/html; charset=utf-8" %>

<%@ include file="/WEB-INF/jsp/includeTop.jsp" %>
<%@ include file="/WEB-INF/jsp/includeTaglib.jsp" %>
<table width="100%" border="0" cellpadding="0" cellspacing="5">
  <tr>
    <td valign="top">
      <table class="dbborder" width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td valign="bottom" class="blueTableBg">&nbsp;我的计划任务&nbsp;-&nbsp;新增工作计划</td>
        </tr>
        <tr>
          <td>
            <table width="100%" border="0" cellpadding="0" cellspacing="5">
              <tr>
                <td>
                  <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td class="dashTopLeft"><img src="images/spacer.gif" width="7" height="7"></td>
                      <td class="dashTop" width=100%><img src="images/spacer.gif" width="7" height="7"></td>
                      <td class="dashTopRight"><img src="images/spacer.gif" width="7" height="7"></td>
                    </tr>
                    <tr>
                      <td class="dashLeft"><img src="images/spacer.gif" width="7" height="7"></td>
                      <td align="center">
                        <table width="100%" border="0" cellpadding="0" cellspacing="3">
                          <form id="newMsgTemplateForm" method="post">
                          <tr>
                            <td width="114" height="20" class="globalText">短信模板描述</td>
                            <td height="20" class="globalText">
                            	<input type="text" id="smsDescription" class="txtbox" size="20" name="smsDescription" value=""/>
                            </td>
                          </tr>
                          <tr>
                            <td width="114" height="20" class="globalText">计划日期</td>
                            <td height="20" class="globalText">
                            	<input onclick="WdatePicker({dateFmt:'yyyy-MM-dd'});" type="text" id="smsDescription" class="txtbox" size="20" name="smsDescription" value=""/>
                            </td>
                          </tr>
                          
                          <tr>
                            <td width="114" height="20" class="globalText">项目及任务信息</td>
                            <td height="20" class="globalText">
                            	<input type="button" class=" btnStyle" value="+添加项目" onclick="javascript:addProject()" />
                            </td>
                          </tr>
                          <tr>
                            <td colspan="2">
                            	<table id="mainTable" width="100%" border="0" cellpadding="0" cellspacing="3">
                            	</table>
                            </td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td align="center" colspan="2">
                              <table border="0" cellpadding="0" cellspacing="2">
                                <tr>
                                  <td><input type="button" class="btnStyle" value="  保存  " onclick="javascript:doSubmit()"></td>
                                  <td><input type="button" class="btnStyle" value="  取消  " onclick="javascript:doCancel()"></td>
                                </tr>
                              </table>
                            </td>
                          </tr>
                          </form>
                        </table>
                      </td>
                      <td class="dashRight"><img src="images/spacer.gif" width="7" height="7"></td>
                    </tr>
                    <tr>
                      <td class="dashBottomLeft"><img src="images/spacer.gif" width="7" height="7"></td>
                      <td class="dashBottom" width=100%><img src="images/spacer.gif" width="7" height="7"></td>
                      <td class="dashBottomRight"><img src="images/spacer.gif" width="7" height="7"></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>



<div style="display:none;">
		<table>
								  <tr id="projectTr">
		                          	<td colspan="2">
		                          		<table class="dbborder" width="100%" border="0" cellpadding="0" cellspacing="1">
								         <tr class="rowHead">
								           <td colspan="5" width="25%" height="20" nowrap align="center" class="globalTextBold">
								           		项目
								           		<input id="project_name_" type="text" />
								           		<input projectIndex="" class="dynamic btnStyle" type="button" value="选择项目" onclick="var a=window.showModalDialog('projectbrowserList.html',window,'status:no;resizable:no;directories:no;help:no;scroll:no;dialogWidth=300px;dialogHeight=180px;dialogLeft:500px;dialogTop:300px;');
																					        $('#project_name_'+this.getAttribute('projectIndex')).val(a+this.getAttribute('projectIndex'));
										 											  " />
								           </td>
								           <td colspan="5" width="55%" height="20" nowrap align="center" class="globalTextBold">
								           </td>
								           <td colspan="1" width="20%" height="20" nowrap align="center" class="globalTextBold">
								           		<input projectIndex="" class="dynamic btnStyle"  value="+添加任务" type="button" onclick="addTask(this.getAttribute('projectIndex'))" />
								           </td>
								         </tr>
								         <tbody id="task_list_">
								         	
								         </tbody>
								       </table>
		                          	</td>
		                          </tr>
		                          
		                          <tr id="spacingTr">
		                          	<td colspan="2">
		                          		&nbsp;
		                          	</td>
		                          </tr>


									<tr class="dynamic_task" id="taskTr" class="rowEven">
							         	<td class="taskNum dynamic globalText" taskIndex="" projectIndex=""height="20">
										</td>
							         	<td height="20" class="globalText">
							         		<input id="task_name_"  style="width: 55px;" type="text" />
										</td>
							         	<td height="20" class="globalText">
							         		<input taskIndex="" class="dynamic btnStyle" value="选择" type="button" onclick="var a=window.showModalDialog('projectbrowserList.html',window,'status:no;resizable:no;directories:no;help:no;scroll:no;dialogWidth=300px;dialogHeight=180px;dialogLeft:500px;dialogTop:300px;');
							         													$('#task_name_'+this.getAttribute('taskIndex')).val(a+this.getAttribute('taskIndex'));
								 											  		" />
							         	</td>
							         	<td height="20" class="globalText">
							         		终端信息
							         	</td>
							         	<td height="20" class="globalText">
							         		<input id="terminal_info_" style="width: 55px;" type="text" />
							         	</td>
							         	<td height="20" class="globalText">
							         		<input taskIndex="" class="dynamic btnStyle" value="选择" type="button" onclick="var a=window.showModalDialog('projectbrowserList.html',window,'status:no;resizable:no;directories:no;help:no;scroll:no;dialogWidth=300px;dialogHeight=180px;dialogLeft:500px;dialogTop:300px;');
							         													$('#terminal_info_'+this.getAttribute('taskIndex')).val(a+this.getAttribute('taskIndex'));
								 											  		" />
							         	</td>
							         	<td height="20" class="globalText">
							         		开始时间
							         	</td>
							         	<td height="20" class="globalText">
							         		<input onclick="WdatePicker({dateFmt:'HH:mm'});" style="width: 55px;" type="text" />
							         	</td>
							         	<td height="20" class="globalText">
							         		截止时间
							         	</td>
							         	<td height="20" class="globalText">
							         		<input onclick="WdatePicker({dateFmt:'HH:mm'});" style="width: 55px;" type="text" />
							         	</td>
							         	<td height="20" class="globalText">
							         		<input projectIndex="" class="dynamic btnStyle" taskIndex="" onclick="javascript:delTask(this)"  type="button" class="" value="删  除" onclick="javascript:doSubmit()">
							         	</td>
							         </tr>
							         
	</table>
</div>

<script type="text/javascript">
	
	var projectIndex=1;
	
	var taskIndex=1;
	
	function addProject(){
		var projectTr=$('#projectTr').clone(true);
		$(projectTr).removeAttr("id");
		$(projectTr).find(".dynamic").each(function(i){
			if($(this).attr("projectIndex")!=null){
				$(this).attr("projectIndex",projectIndex);
			}
		});
		$(projectTr).find("#project_name_")[0].setAttribute("id","project_name_"+projectIndex);
		$(projectTr).find("#task_list_")[0].setAttribute("id","task_list_"+projectIndex);
		$("#mainTable").append(projectTr);
		
		$("#mainTable").append($('#spacingTr').clone(true));
		
		projectIndex++;
	}
	
	function addTask(projectIndex){
		taskIndex++;
		var taskTr=$('#taskTr').clone(true);
		$(taskTr).attr("id","taskTr_"+projectIndex+"_"+(taskIndex));
		//$(taskTr).find("#del_task_button_")[0].setAttribute("id","del_task_button_"+taskIndex);
		$(taskTr).find("#task_name_")[0].setAttribute("id","task_name_"+taskIndex);
		$(taskTr).find("#terminal_info_")[0].setAttribute("id","terminal_info_"+taskIndex);
		
		
		$(taskTr).find(".dynamic").each(function(i){
			if($(this).attr("taskIndex")!=null){
				$(this).attr("taskIndex",taskIndex);
			}
			if($(this).attr("projectIndex")!=null){
				$(this).attr("projectIndex",projectIndex);
			}
		});
		
		$("#task_list_"+projectIndex).append(taskTr);
		
		showTaskNum(projectIndex);
	}
	
	function delTask(delBtn){
		//if(!confirm('删除任务?')){
		//	return;
		//}
		var trId='taskTr_'+$(delBtn).attr('projectIndex')+"_"+$(delBtn).attr('taskIndex')
		$("#"+trId).remove();
		
		showTaskNum($(delBtn).attr('projectIndex'));
	}
	
	function showTaskNum(projectIndex){
		var i=1;
		$(".taskNum").each(function(){
			if($(this).attr('projectIndex')==projectIndex){
				$(this).html('任务'+(i++));
			}			
		});
	}
</script>
